﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace ResolutionManager
{
    static class Program
    {
        /// <summary>
        /// Der Haupteinstiegspunkt für die Anwendung.
        /// </summary>
        [STAThread]
        static void Main()
        {
            //Kill itself cause otherwise the OS cannot shutdown
            Microsoft.Win32.SystemEvents.SessionEnding += new Microsoft.Win32.SessionEndingEventHandler(SystemEvents_SessionEnding);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            //Initial application style
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //Run application
            Application.Run(new ResolutionManagerContext());
        }

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            if (e.ExceptionObject is Exception)
            {
                MessageBox.Show("There is an error while application executing: " + ((Exception)e.ExceptionObject).Message + "\nApplication will be exit!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("There is an unknown error while application executing!\nApplication will be exit!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private static void SystemEvents_SessionEnding(object sender, Microsoft.Win32.SessionEndingEventArgs e)
        {
            Application.Exit();
        }
    }
}
